<?php

if(!defined("INDEX"))
    die;

if(!check_request('action'))
    die;

// ----------------------------------------------------------------------------

if (@$_REQUEST['action'] == 'leaked' && isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {

    if(!check_request('release_id'))
        die;

    echo json_encode(leaked_release($_REQUEST['release_id']));
    exit;
}

elseif (@$_REQUEST['action'] == 'unleaked' && isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {

    if(!check_request('release_id'))
        die;

    echo json_encode(unleaked_release($_REQUEST['release_id']));
    exit;
}

function leaked_release($release_id)
{

    $response = array
    (
        'ok' => false,
        'msg' => _("fail")
    );

    try {

        $release = Release::getById($release_id);

        if($release instanceof Release) {

            $release->markAsLeaked(true);


            $response = array
            (
                'ok' => true,
                'msg' => _("OK")
            );
        }

    } catch (Exception $e) {

        // ...
    }

    return $response;
}

function unleaked_release($release_id)
{

    $response = array
    (
        'ok' => false,
        'msg' => _("fail")
    );

    try {

        $release = Release::getById($release_id);

        if($release instanceof Release) {

            $release->markAsLeaked(false);

            $response = array
            (
                'ok' => true,
                'msg' => _("OK")
            );
        }

    } catch (Exception $e) {

        // ...
    }

    return $response;
}